import { createRouter, createWebHashHistory } from "vue-router";

const Home = () => import("/@/views/Home/index.vue"); // 首页
const CarInfo = () => import("/@/views/CarInfo/CarInfo.vue");
const ApprovalList = () =>
  import("/@/components/ApprovalList/ApprovalList.vue"); // 审批单

const TripPeople = () => import("../components/TripPeople/TripPeople.vue"); // 出行人
const CarCommonlyAddress = () =>
  import("../components/CarCommonlyAddress/CarCommonlyAddress.vue"); // 出行人
const AddTripPeople = () =>
  import("../components/TripPeople/AddTripPeople/AddTripPeople.vue"); // 添加出行人
const SearchTripPeople = () =>
  import("../components/TripPeople/SearchTripPeople/SearchTripPeople.vue"); // 搜索出行人
const CarOrderList = () =>
  import("../components/CarOrderList/CarOrderList.vue"); // 用车订单列表
const CarOrderDetail = () =>
  import("../components/CarOrderList/CarOrderDetail.vue"); // 用车订单列表
const reserveOrder = () => import("/@/views/reserveOrder/reserveOrder.vue"); // 预订页

const OrderMap = () => import("/@/views/OrderMap/OrderMap.vue"); // 订单地图
const CarCashier = () => import("/@/views/Cashier/Cashier.vue"); // 用车支付
const CashierSuccess = () => import("/@/views/Cashier/CashierSuccess.vue"); // 支付成功

const routes = [
  {
    path: "/",
    redirect: "/home",
    name: "首页",
    component: Home
  },
  {
    path: "/home",
    name: "home",
    component: Home,
    children: [
      {
        path: "/home/carCommonlyAddress",
        name: "常用地址",
        component: CarCommonlyAddress
      },
      {
        path: "/home/approvalList",
        name: "选择审批单",
        component: ApprovalList
      },
      {
        path: "/home/tripPeople",
        name: "出行人",
        component: TripPeople,
        children: [
          {
            path: "/home/tripPeople/addTripPeople",
            name: "添加出行人",
            component: AddTripPeople
          },
          {
            path: "/home/tripPeople/searchTripPeople",
            name: "搜索出行人",
            component: SearchTripPeople
          }
        ]
      }
    ]
  },
  {
    path: "/carOrderList",
    name: "订单列表",
    component: CarOrderList
  },
  {
    path: "/CarOrderDetail",
    name: "订单详情",
    component: CarOrderDetail
  },
  {
    path: "/carInfo",
    name: "用车询价列表",
    component: CarInfo
  },
  {
    path: "/reserveOrder",
    name: "预订页",
    component: reserveOrder
  },
  {
    path: "/orderMap",
    name: "订单地图",
    component: OrderMap
  },
  {
    path: "/CarCashier",
    name: "支付页面",
    component: CarCashier
  },
  {
    path: "/CashierSuccess",
    name: "支付成功",
    component: CashierSuccess
  }
];

const router = createRouter({
  history: createWebHashHistory(),
  routes
});

// Vue跳转到新页面，默认在顶部
// router.afterEach((to, from, next) => {
//   window.scrollTo(0, 0);
// });

export default router;
